 

import Control.TradeController;
import Model.*;

/**
 * UI for Rents
 * @author Stefan
 */
public class RentUI {
    private TradeController tradeCtl = TradeController.getInstance();

    /**
     * Start Rent menu
     */
    public void start()
    {
        rentMenu();
    }

    /**
     * Rent menu
     */
    private void rentMenu()
    {
        boolean exit = false;
        while (!exit)
        {
            int choise = writeRentMenu();
            if (choise == 1)
            {
                
            }
            else if (choise == 2)
            {
                startRead(CommonUIFunctions.readString("\n write ID: "));
            }
            else if (choise == 3)
            {
                startUpdate(CommonUIFunctions.readString("\n write ID: "));
            }
            else if(choise == 4)
            {
                startDelete(CommonUIFunctions.readString("\n write ID: "));
            }
            else
            {
                exit = true;
            }
        }
    }

    /**
     * Print Rent menu
     * @return int based on your choise
     */
    private int writeRentMenu()
    {
        System.out.println("\f *** Rent Menu ***");
        System.out.println(" (1) Create");
        System.out.println(" (2) Read");
        System.out.println(" (3) Update");
        System.out.println(" (4) Delete");
        System.out.println(" (0) Back");

        return CommonUIFunctions.readInt("\n Make your choise: ");
    }

    /**
     * Get info about Rent
     * @param ID
     */
    private void getInfo(String ID)
    {
        Rent rent = tradeCtl.findRent(ID);
        System.out.println("Rent");
        System.out.println("Id: " + rent.getId());
        for(SalesLineItem item : rent.getSaleLines())
        {
            System.out.println(item.getProduct() + " " + item.getQuantity());
        }
        System.out.println("Rental Period: " + rent.getRentalPeriod());
        System.out.println("Total price: " + rent.totalPrice());
    }

    /**
     * Read Rent
     * @param ID
     */
    private void startRead(String ID)
    {
        try
        {
            Rent rent = tradeCtl.findRent(ID);
            getInfo(ID);
        } catch (Exception e)
        {
            System.out.println("There was no rent with this ID: " + (ID));
        }
    }

    /**
     * Delete menu
     * @param ID
     */
    private void startDelete(String ID)
    {
        try
        {
            Rent rent = tradeCtl.findRent(ID);
            getInfo(ID);
            tradeCtl.deleteTrade(ID);
            System.out.println("Rent " + (ID) + " was deleted");
        } catch (Exception e)
        {
            System.out.println("There was no rent with this ID: " + (ID));
        }

    }

    /**
     * Update menu
     * @param ID
     */
    private void startUpdate(String ID)
    {
        try
        {
            Rent rent = tradeCtl.findRent(ID);
            getInfo(ID);
            //updateMenu(rent);
        } catch (Exception e)
        {
            System.out.println("There was no rent with this ID: " + (ID));
        }
    }

//    private void updateMenu(Product pro)
//    {
//        boolean exit = false;
//        while (!exit)
//        {
//            int choise = writeUpdateMenu();
//            if (choise == 1)
//            {
//                pro.setId(CommonUIFunctions.readString("\n write new ID: "));
//            } else if (choise == 2)
//            {
//                pro.setName(CommonUIFunctions.readString("\n write new name: "));
//            } else if (choise == 3)
//            {
//                pro.setDescription(CommonUIFunctions.readString("\n write new description: "));
//            } else if (choise == 4)
//            {
//                pro.setPrice(CommonUIFunctions.readDouble("\n write new price: "));
//            } else if (choise == 5)
//            {
//                pro.setRentalPrice(CommonUIFunctions.readDouble("\n write new rental price: "));
//            } else if (choise == 6)
//            {
//                pro.setSale(CommonUIFunctions.readDouble("\n write new sales percent (0-100): "));
//            } else
//            {
//                exit = true;
//            }
//        }
//    }

}
